<h3><B>问题管理</B></h3>


<a class="btn btn-default btn-xs" href="/#/question/add">小6客服群发问题</a>
<br>
<paging>
    <ul class="pagination" num-pages="tasks.pageCount" current-page="tasks.currentPage"
        on-select-page="selectPage(page)">
        <li ng-class="{disabled: noPrevious()}"><a ng-click="selectPrevious()">&laquo;</a>

        </li>
        <li ng-repeat="page in pages" ng-class="{active: isActive(page)}"><a
                ng-click="selectPage(page)">{{page}}</a>

        </li>
        <li ng-class="{disabled: noNext()}"><a ng-click="selectNext()">&raquo;</a>

        </li>
        <li ng-show="currentPage>6"><a ng-click="selectPage(1)">首页</a>

        </li>
    </ul>
</paging>

<form class="form-inline">
    <div class="form-group">
        <p id="errorMsg" class="text-danger" ng-show="showErrorForQueryCondition==true"></p>
        <label class="control-label" for="textinput">小区:</label>
        <select ng-model="communityId" ng-options="m.objId as m.communityName for m in communityLabelList.data">
            <!--ng-change="selectCondition(communityId,category,description)">-->
            <option value="">-- 请选择 --</option>
        </select>
        <label class="control-label" for="textinput">分类:</label>
        <select ng-model="category" ng-options="c.value as c.name for c in categoryList">
            <!--ng-change="selectCondition(communityId,category,description)">-->
            <option value="">全部</option>
        </select>
        <label class="control-label" for="textinput">标签:</label>
        <select ng-model="tagflg">
            <option value="all">全部</option>
            <option value="yes">有标签</option>
            <option value="no">无标签</option>
        </select>
        <label class="control-label" for="textinput">回复:</label>
        <select ng-model="replieflg">
            <!--<option value="? object:null ?"></option>-->
            <option value="all">全部</option>
            <option value="yes">有</option>
            <option value="no">无</option>
        </select>
        <label class="control-label" for="textinput">精华帖:</label>
        <select ng-model="level">
            <!--<option value="? object:null ?"></option>-->
            <option value="all">全部</option>
            <option value="yes">精华帖</option>
            <option value="no">非精华帖</option>
        </select>

        <!--<label class="control-label" for="textinput">零回复:</label>-->
        <!--<div class="checkbox">-->
        <!--<label>-->
        <!--<input type="checkbox" class="form-control" ng-model="replieflg" >-->
        <!--</label>-->
        <!--</div>-->

        <label class="control-label" for="textinput">创建者:</label>
        <input type="text" class="form-control" placeholder="" style="margin-left:0px;width: 200px" ng-model="nickname">

        <label class="control-label" for="textinput">关键字:</label>
        <input type="text" class="form-control" placeholder="" style="margin-left:0px;width: 200px"
               ng-model="description">

        <br>
        <!--<input type="text" class="form-control" placeholder="用户id" style="margin-left: 20px;width: 200px" required-->
        <!--ng-model="userId">-->
        <!--<button type="submit" class="btn btn-default" ng-click="searchUserQuestion(userId)">搜索</button>-->
        发布时间：
        <input type="text" id="startDate" class="form-control datepicker" size="12" data-date-format="yyyy-mm-dd">
        至：
        <input type="text" id="endDate" class="form-control datepicker" size="12" data-date-format="yyyy-mm-dd">

        <button type="submit" id="btnSearch" class="form-control btn btn-secondary"
                ng-click="selectCondition(communityId,category,tagflg,replieflg,nickname,description,level)">搜索
        </button>
        <!--<button type="submit" class="form-control btn btn-secondary" >Search</button>-->

    </div>
</form>

<div class="tab-content" style="margin-top: 20px">
    <div class="tab-pane active" id="tab_b">
        <table class="table table-condensed">
            <thead>
            <tr>

                <th>所属小区<!--community--></th>
                <th>标签<!--status--></th>
                <th>浏览次数<!--browserCount--></th>
                <th>描述<!--desc--></th>
                <th>回复/数量</th>
                <th>创建者<!--createdBy--></th>
                <th>发布时间<!--createdBy--></th>
                <th>最后修改时间<!--dateLastModified--></th>
                <th>分类</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="question in recommendList">

                <td width="150">{{question.community.communityName}}</td>
                <td width="150"><span ng-repeat="t in question.tag">{{t}} </span></td>
                <td width="100">{{question.browserCount}}</td>
                <td width="400">{{question.desc}}</td>
                <td>
                    <a data-toggle="modal" data-target="#resModal{{$index}}">查看</a>/
                    {{question.replies.length}}
                    <div class="modal fade" id="resModal{{$index}}" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"
                                            aria-label="Close"><span
                                            aria-hidden="true">&times;</span></button>
                                    <h5 class="modal-title" id="myModalLabel">问题：{{question.desc}}</h5>
                                </div>
                                <div class="modal-body">
                                    <table class="table table-condensed">
                                        <thead>
                                        <tr>
                                            <th>回复</th>
                                            <th>回复者</th>
                                            <th align="right">回复时间</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr ng-repeat="r in question.replies">

                                            <td width="200">{{r.replyDesc}}</td>
                                            <td width="100">{{r.repliedBy.nickName}}</td>
                                            <td width="150">{{r.dateReplied | date:'yyyy-MM-dd HH:mm:ss'}}</td>

                                        </tr>
                                        </tbody>
                                    </table>
                                    <input type="text" class="form-control" placeholder="回复内容..."
                                           ng-model="data.replies.replyDesc">
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary btn-sm"
                                            ng-click="sendReply(question.objId,data)">回复
                                    </button>
                                    <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">关闭
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
                <td>{{question.createdBy.nickName}}</td>
                <td>{{question.dateCreated | date:'yyyy-MM-dd HH:mm:ss'}}</td>
                <td>{{question.dateLastModified | date:'yyyy-MM-dd HH:mm:ss'}}</td>
                <td>
                    <select ng-model="question.category" ng-options="c.value as c.name for c in categoryList"
                            ng-change="changeCategory(question.objId,question.category)">
                        <option value="">-- 请选择 --</option>
                    </select>
                </td>
                <td width="350">
                    <a class="btn btn-default btn-xs" ng-click="gotoQuestionEditPage(question.objId)">编辑</a>

                    <span ng-if="category !=null">
                        <a class="btn btn-primary btn-xs" ng-show="question.categoryOrder==null&&communityId!=null"
                           ng-click="moveToTop(question.objId)">置顶</a>
                    <a class="btn btn-danger btn-xs" ng-show="question.categoryOrder!=null&&communityId!=null"
                       ng-click="cancelTop(question.objId)">取消</a>
                    </span>

                     <span ng-if="category ==null">
                        <a class="btn btn-primary btn-xs" ng-show="question.allOrder==null&&communityId!=null"
                           ng-click="moveToTop(question.objId)">置顶</a>
                    <a class="btn btn-danger btn-xs" ng-show="question.allOrder!=null&&communityId!=null"
                       ng-click="cancelTop(question.objId)">取消</a>
                    </span>

                    <a class="btn btn-secondary btn-xs" ng-click="deleteQuestion(question.objId)">删除</a>
                    <a class="btn btn-primary btn-xs" ng-show="question.isFresh !=true" data-toggle="modal"
                       data-target="#fresh{{$index}}"
                       ng-click="">添加新鲜事</a>

                    <div class="modal fade" id="fresh{{$index}}" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabel" aria-hidden="false">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"
                                            aria-label="Close"><span
                                            aria-hidden="true">&times;</span></button>
                                    <h5 class="modal-title" id="myFresh">问题：{{question.desc}}</h5>
                                </div>
                                <div class="modal-body">
                                    <h6 class="modal-title" id="myFresh1">请输入标题：</h6>
                                    <textarea rows="5" ng-model="title" required style="width:100%"
                                              tabindex="7"></textarea>
                                </div>
                                <div class="modal-footer">
                                    <button ng-click="addToFreshNews(question,title)" type="button"
                                            class="btn btn-default btn-sm" data-dismiss="modal">确定
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <a ng-show="question.isFresh == true">已在新鲜事</a>

                    <a ng-show="question.level !=1" class="btn btn-secondary btn-xs"
                       ng-click="changeLevel(question.objId,1)">设置精华贴</a>
                    <a ng-show="question.level ==1" class="btn btn-danger btn-xs"
                       ng-click="changeLevel(question.objId,0)">取消精华贴</a>

                        <span ng-show="question.tag!=null&&question.tag.length>0"> <a class="btn btn-secondary btn-xs"
                                                                                      ng-click="pushQuestion(question)">推送</a>
                            </span>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<div class="modal fade" id="pushModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">推送内容：</h4>
            </div>
            <div class="modal-body">
                <p>
                <ul>
                    <li>问题： {{pushMessage.question.desc}}</li>
                    <li>标签： <span ng-repeat="t in pushMessage.question.tag">{{t}} </span></li>
                    <li>创建者： {{pushMessage.question.createdBy.nickName}}</li>
                    <li>预计发送人数：{{pushMessage.uList.length}}</li>
                </ul>

                </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="confirmPush()">发送</button>

            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="userQuestion">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">问答列表：</h4>
            </div>
            <div class="modal-body">
                <table class="table table-condensed">
                    <thead>
                    <tr>
                        <th>类型</th>
                        <th>问题</th>
                        <th>回复</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="quesiton in userQuestionList">

                        <td width="50"><span ng-show="quesiton.isCreated ==true">提问</span>
                            <span ng-show="quesiton.isCreated ==false">回复</span>
                        </td>
                        <td>{{quesiton.desc}}</td>
                        <td>{{quesiton.myReply}}</td>

                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button"
                        class="btn btn-default btn-sm" data-dismiss="modal">关闭
                </button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<paging>
    <ul class="pagination" num-pages="tasks.pageCount" current-page="tasks.currentPage"
        on-select-page="selectPage(page)">
        <li ng-class="{disabled: noPrevious()}"><a ng-click="selectPrevious()">&laquo;</a>

        </li>
        <li ng-repeat="page in pages" ng-class="{active: isActive(page)}"><a
                ng-click="selectPage(page)">{{page}}</a>

        </li>
        <li ng-class="{disabled: noNext()}"><a ng-click="selectNext()">&raquo;</a>

        </li>
        <li ng-show="currentPage>6"><a ng-click="selectPage(1)">首页</a>

        </li>
    </ul>
</paging>

<script>


    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, //month
            "d+": this.getDate(), //day
            "h+": this.getHours(), //hour
            "m+": this.getMinutes(), //minute
            "s+": this.getSeconds(), //second
            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
            "S": this.getMilliseconds() //millisecond
        }
        if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
                (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o) if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
                    RegExp.$1.length == 1 ? o[k] :
                            ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    }

    var fromDate = $('#startDate').datepicker().on('changeDate', function (ev) {
        //alert(ev.date.format('yyyy-MM-dd'));
        //$scope.startDate=ev.date.format('yyyy-MM-dd');
        $("#startDate").val(ev.date.format('yyyy-MM-dd'));
//        alert(ev.date);
    });

    var toDate = $('#endDate').datepicker().on('changeDate', function (ev) {
        // alert(ev.date.format('yyyy-MM-dd'));
        //$scope.endDate=ev.date.format('yyyy-MM-dd');
        $("#endDate").val(ev.date.format('yyyy-MM-dd'));
    });


</script>